from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-10 14:06:16.132523
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 10, Feb, 2022
Time: 14:06:22
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.0579
Nobs: 563.000 HQIC: -48.4802
Log likelihood: 6623.54 FPE: 6.72796e-22
AIC: -48.7506 Det(Omega_mle): 5.74206e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350012 0.068964 5.075 0.000
L1.Burgenland 0.106108 0.041963 2.529 0.011
L1.Kärnten -0.110715 0.021798 -5.079 0.000
L1.Niederösterreich 0.194457 0.087578 2.220 0.026
L1.Oberösterreich 0.130436 0.086491 1.508 0.132
L1.Salzburg 0.254509 0.044358 5.738 0.000
L1.Steiermark 0.035218 0.058481 0.602 0.547
L1.Tirol 0.099376 0.047200 2.105 0.035
L1.Vorarlberg -0.071196 0.041730 -1.706 0.088
L1.Wien 0.019147 0.076857 0.249 0.803
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056591 0.149253 0.379 0.705
L1.Burgenland -0.040969 0.090818 -0.451 0.652
L1.Kärnten 0.041243 0.047174 0.874 0.382
L1.Niederösterreich -0.198872 0.189537 -1.049 0.294
L1.Oberösterreich 0.459843 0.187186 2.457 0.014
L1.Salzburg 0.281892 0.096000 2.936 0.003
L1.Steiermark 0.112891 0.126565 0.892 0.372
L1.Tirol 0.304069 0.102150 2.977 0.003
L1.Vorarlberg 0.023020 0.090312 0.255 0.799
L1.Wien -0.029805 0.166335 -0.179 0.858
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196605 0.035182 5.588 0.000
L1.Burgenland 0.090257 0.021408 4.216 0.000
L1.Kärnten -0.007329 0.011120 -0.659 0.510
L1.Niederösterreich 0.235392 0.044678 5.269 0.000
L1.Oberösterreich 0.165782 0.044124 3.757 0.000
L1.Salzburg 0.039871 0.022629 1.762 0.078
L1.Steiermark 0.026515 0.029834 0.889 0.374
L1.Tirol 0.082270 0.024079 3.417 0.001
L1.Vorarlberg 0.055153 0.021288 2.591 0.010
L1.Wien 0.117257 0.039209 2.991 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121461 0.035253 3.445 0.001
L1.Burgenland 0.043401 0.021451 2.023 0.043
L1.Kärnten -0.013218 0.011143 -1.186 0.236
L1.Niederösterreich 0.170020 0.044768 3.798 0.000
L1.Oberösterreich 0.335965 0.044213 7.599 0.000
L1.Salzburg 0.099896 0.022675 4.406 0.000
L1.Steiermark 0.110353 0.029895 3.691 0.000
L1.Tirol 0.090214 0.024128 3.739 0.000
L1.Vorarlberg 0.060831 0.021331 2.852 0.004
L1.Wien -0.019023 0.039288 -0.484 0.628
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125531 0.066367 1.891 0.059
L1.Burgenland -0.048470 0.040383 -1.200 0.230
L1.Kärnten -0.045346 0.020977 -2.162 0.031
L1.Niederösterreich 0.140596 0.084280 1.668 0.095
L1.Oberösterreich 0.164627 0.083234 1.978 0.048
L1.Salzburg 0.284140 0.042688 6.656 0.000
L1.Steiermark 0.056905 0.056279 1.011 0.312
L1.Tirol 0.155758 0.045422 3.429 0.001
L1.Vorarlberg 0.095044 0.040158 2.367 0.018
L1.Wien 0.074496 0.073963 1.007 0.314
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080892 0.051799 1.562 0.118
L1.Burgenland 0.024725 0.031519 0.784 0.433
L1.Kärnten 0.053351 0.016372 3.259 0.001
L1.Niederösterreich 0.191096 0.065780 2.905 0.004
L1.Oberösterreich 0.329139 0.064964 5.066 0.000
L1.Salzburg 0.033432 0.033318 1.003 0.316
L1.Steiermark 0.005322 0.043925 0.121 0.904
L1.Tirol 0.120130 0.035452 3.389 0.001
L1.Vorarlberg 0.066242 0.031343 2.113 0.035
L1.Wien 0.097626 0.057728 1.691 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171789 0.062577 2.745 0.006
L1.Burgenland 0.003042 0.038077 0.080 0.936
L1.Kärnten -0.065786 0.019779 -3.326 0.001
L1.Niederösterreich -0.109897 0.079467 -1.383 0.167
L1.Oberösterreich 0.212095 0.078481 2.703 0.007
L1.Salzburg 0.053153 0.040250 1.321 0.187
L1.Steiermark 0.248896 0.053065 4.690 0.000
L1.Tirol 0.498906 0.042828 11.649 0.000
L1.Vorarlberg 0.065612 0.037865 1.733 0.083
L1.Wien -0.074467 0.069739 -1.068 0.286
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161133 0.069314 2.325 0.020
L1.Burgenland -0.005110 0.042177 -0.121 0.904
L1.Kärnten 0.062449 0.021908 2.850 0.004
L1.Niederösterreich 0.175630 0.088023 1.995 0.046
L1.Oberösterreich -0.061364 0.086931 -0.706 0.480
L1.Salzburg 0.205706 0.044583 4.614 0.000
L1.Steiermark 0.137971 0.058778 2.347 0.019
L1.Tirol 0.056223 0.047440 1.185 0.236
L1.Vorarlberg 0.144478 0.041942 3.445 0.001
L1.Wien 0.126416 0.077247 1.637 0.102
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.393724 0.040615 9.694 0.000
L1.Burgenland -0.003357 0.024713 -0.136 0.892
L1.Kärnten -0.021216 0.012837 -1.653 0.098
L1.Niederösterreich 0.199738 0.051577 3.873 0.000
L1.Oberösterreich 0.231995 0.050937 4.555 0.000
L1.Salzburg 0.036275 0.026124 1.389 0.165
L1.Steiermark -0.017588 0.034441 -0.511 0.610
L1.Tirol 0.090643 0.027797 3.261 0.001
L1.Vorarlberg 0.052184 0.024576 2.123 0.034
L1.Wien 0.040652 0.045263 0.898 0.369
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035113 0.104952 0.168440 0.133958 0.095745 0.080909 0.029565 0.212008
Kärnten 0.035113 1.000000 -0.025932 0.132461 0.046994 0.085584 0.444167 -0.068058 0.090438
Niederösterreich 0.104952 -0.025932 1.000000 0.312090 0.123991 0.269866 0.065457 0.155871 0.283910
Oberösterreich 0.168440 0.132461 0.312090 1.000000 0.214474 0.293516 0.167833 0.134951 0.235450
Salzburg 0.133958 0.046994 0.123991 0.214474 1.000000 0.124320 0.090796 0.103384 0.126813
Steiermark 0.095745 0.085584 0.269866 0.293516 0.124320 1.000000 0.133999 0.105378 0.030671
Tirol 0.080909 0.444167 0.065457 0.167833 0.090796 0.133999 1.000000 0.062974 0.151367
Vorarlberg 0.029565 -0.068058 0.155871 0.134951 0.103384 0.105378 0.062974 1.000000 -0.004885
Wien 0.212008 0.090438 0.283910 0.235450 0.126813 0.030671 0.151367 -0.004885 1.000000